package com.magicsoft.share.ui.share;

import android.content.Intent;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.magicsoft.share.R;
import com.magicsoft.share.adapter.share.SpecialListAdapter;
import com.magicsoft.share.base.BaseActivity;
import com.magicsoft.share.bean.share.Special;
import com.magicsoft.share.presenter.share.SpecialListPresenter;
import com.magicsoft.share.view.share.ISpecialListView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class SpecialListActivity extends BaseActivity<ISpecialListView,SpecialListPresenter> implements ISpecialListView {


    @BindView(R.id.view_top)
    View viewTop;
    @BindView(R.id.ibtn_left)
    ImageButton ibtnLeft;
    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.ibtn_right)
    ImageButton ibtnRight;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private SpecialListAdapter specialListAdapter;
    private int articleTypeId;

    @Override
    public SpecialListPresenter initPresenter() {
        return new SpecialListPresenter();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_special_list;
    }

    @Override
    public void initData() {

        articleTypeId = getIntent().getIntExtra("articleTypeId", -1);

    }

    @Override
    public void initView() {
        tvTitle.setText("专题列表");
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));

        specialListAdapter = new SpecialListAdapter(R.layout.item_special_list);
        specialListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Special item = specialListAdapter.getItem(position);
                Intent intent = new Intent(SpecialListActivity.this, SpecialActivity.class);

                intent.putExtra("special", item);
                startActivity(intent);
            }
        });
        recyclerView.setAdapter(specialListAdapter);

    }

    @Override
    public void requestData() {
        mPresenter.articleSpecialList(articleTypeId);
    }


    @OnClick(R.id.ibtn_left)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void specialListSuccess(List<Special> specials) {
        specialListAdapter.setNewData(specials);
    }
}
